// import Home from '@/pages/Home'
// 路由懒加载
// const Home = () => import ('@/pages/Home')
// import Login from '@/pages/Login'
// import Register from '@/pages/Register'
// import Search from '@/pages/Search'
// import Detail from '@/pages/Detail'
// import AddCartSuccess from '@/pages/AddCartSuccess'
// import ShopCart from '@/pages/ShopCart'
// import Pay from '@/pages/Pay'
// import PaySuccess from '@/pages/PaySuccess'
// import Trade from '@/pages/Trade'
// import Center from '@/pages/Center'
// import MyOrder from '@/pages/Center/MyOrder'
// import GroupOrder from '@/pages/Center/GroupOrder'
const Register = () => import ('@/pages/Register')
const Login = () => import ('@/pages/Login')
const Search = () => import ('@/pages/Search')
const Detail = () => import ('@/pages/Detail')
const AddCartSuccess = () => import ('@/pages/AddCartSuccess')
const ShopCart = () => import ('@/pages/ShopCart')
const Pay = () => import ('@/pages/Pay')
const PaySuccess = () => import ('@/pages/PaySuccess')
const Trade = () => import ('@/pages/Trade')
const Center = () => import ('@/pages/Center')
const MyOrder = () => import ('@/pages/Center/MyOrder')
const GroupOrder = () => import ('@/pages/Center/GroupOrder')
export default [
    {
        path:'/center',//个人中心
        component:Center,
        children:[
            {
                path:'myorder',//我的订单
                component:MyOrder
            },
            {
                path:'grouporder',//团购订单
                component:GroupOrder
            },
            {
                path:'',//重定向
                redirect:'myorder'
            }
        ]
    },
    {
        path:'/paysuccess',//支付成功页面
        component:PaySuccess,
        beforeEnter: (to, from, next) => {
            // 只有从支付页面才可以跳转到支付成功页面
            if (from.path === '/pay') {
                next()
            }else{
                alert('只有从支付页面才可以跳转到支付成功页面')
                next(false)
            }
        }
    },
    {
        path:'/pay',//支付页面
        component:Pay,
        beforeEnter: (to, from, next) => {
            // 只有从交易页面才可以跳转到支付页面
            if (from.path === '/trade') {
                next()
            }else{
                alert('只有从交易页面才可以跳转到支付页面')
                next(false)
            }
        }
    },
    {
        path:'/trade',//交易页面
        component:Trade,
        beforeEnter: (to, from, next) => {
            // 只有从购物车页面才可以跳转到交易界面
            if (from.path === '/shopcart') {
                next()
            }else{
                alert('只有从购物车页面才可以跳转到交易界面')
                next(false)
            }
        }
    },
    {
        path:'/shopcart',//购物车页面
        component:ShopCart
    },
    {
        path:'/addcartsuccess',//添加购物车成功页面
        component:AddCartSuccess,
        // 路由独享守卫
        // beforeEnter: (to, from, next) => {
        //     // 只有携带了skuNum和sessionStorage内部有skuInfo数据才可以跳转
        //     // 如果没有让跳转到自定义页面
        //     let skuNum = to.query.skuNum
        //     let skuInfo = sessionStorage.getItem('SKUINFO_KEY')
        //     if (skuNum && skuInfo) {
        //         next()
        //     }else{
        //         alert('必须携带skuNum和skuInfo')
        //         next(false)
        //     }
        //   }
    },
    {
        path:'/detail/:skuId',//商品详情页
        component:Detail
    },
    {
        path:'/home',//主页
        component: () => import('@/pages/Home')
        // 注册的时候,可以是组件,也可以是个函数
    },
    {
        path:'/login',//登录页面
        component:Login,
        meta:{isHidden:true}
    },
    {
        path:'/register',//注册页面
        component:Register,
        meta:{isHidden:true}
    },
    {
        name:'search',//搜索页面
        path:'/search/:keyword?',
        component:Search,
        // 第一种 布尔值
        // props:true
        // 第二种  对象
        // props:{userName:'温时辉'}
        // 第三种  函数(最多)
        // props(route){
        //     return{
        //         keyword:route.params.keyword,
        //         keyword1:route.query.keyword1
        //     }
        // }
    },
    {
        path:'/',
        redirect:'/home'//重定向
    },
    {
        path: '/communication',//组件间的高级通讯
        component: () => import('@/pages/Communication/Communication'),
        children: [
          {
            path: 'event',
            component: () => import('@/pages/Communication/EventTest/EventTest'),
            meta: {
              isHideFooter: true
            },
          },
          {
            path: 'model',
            component: () => import('@/pages/Communication/ModelTest/ModelTest'),
            meta: {
              isHideFooter: true
            },
          },
          {
            path: 'sync',
            component: () => import('@/pages/Communication/SyncTest/SyncTest'),
            meta: {
              isHideFooter: true
            },
          },
          {
            path: 'attrs-listeners',
            component: () => import('@/pages/Communication/AttrsListenersTest/AttrsListenersTest'),
            meta: {
              isHideFooter: true
            },
          },
          {
            path: 'children-parent',
            component: () => import('@/pages/Communication/ChildrenParentTest/ChildrenParentTest'),
            meta: {
              isHideFooter: true
            },
          },
          {
            path: 'scope-slot',
            component: () => import('@/pages/Communication/ScopeSlotTest/ScopeSlotTest'),
            meta: {
              isHideFooter: true
            },
          }
        ],
      },
]